<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="关键词：">
          <el-input v-model="listPram.keyword" placeholder="" clearable class="selWidth"/>
        </el-form-item>
        <el-form-item label="审核状态">
          <el-select v-model="listPram.status">
            <el-option :value="-1" label="全部"></el-option>
            <el-option :value="0" label="待审核"></el-option>
            <el-option :value="1" label="已通过"></el-option>
            <el-option :value="2" label="未通过"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click="handleSearch">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>

      </el-form>
      <el-table :data="listData.list"  v-loading="loading" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column
          prop="id"
          label="ID"
          width="50"
        />
        <el-table-column label="标题" prop="title" min-width="140"/>
        <el-table-column label="标签" prop="label" min-width="120"/>
        <el-table-column label="地址" prop="address" min-width="120"/>
        <el-table-column label="状态" prop="statusText" min-width="120"/>
        <el-table-column label="类型" prop="typeText" width="120"/>
        <el-table-column label="操作" min-width="130" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button icon="el-icon-document-checked" type="primary" size="mini" @click="handlerOpenReview(scope.row)" v-has-permi="['admin:entrepreneurship:review']">审核</el-button>
            <el-button icon="el-icon-view" type="success" size="mini" @click="handlerOpenDetail(scope.row)" v-has-permi="['admin:entrepreneurship:detail']">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="listPram.page"
        :page-sizes="constants.page.limit"
        :layout="constants.page.layout"
        :total="listData.count"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
      :visible.sync="detailDialogConfig.visible"
      title="详情"
      destroy-on-close
      :close-on-click-modal="false"
      width="1000px"
    >
      <detail
        v-if="detailDialogConfig.visible"
        :edit-data="detailDialogConfig.editData"
        @hideEditDialog="hideDetailDialog"
      />
    </el-dialog>
    <el-dialog
      :visible.sync="reviewDialogConfig.visible"
      title="审核"
      destroy-on-close
      :close-on-click-modal="false"
      width="700px"
    >
      <review
        v-if="reviewDialogConfig.visible"
        :edit-data="reviewDialogConfig.editData"
        @hideEditDialog="hideReviewDialog"
      />
    </el-dialog>
  </div>
</template>

<script>
import {
  list,
  deleteRow
} from '@/api/entrepreneurship'
import review from './review'
import detail from './detail'
export default {
  components: { detail,review },
  data() {  
    return {
      constants:this.$constants,
      loading:false,
      listData: { list: [] },
      listPram: {
        page: 1,
        limit: this.$constants.page.limit[0],
        keyword:'',
        status:-1,
      },
      reviewDialogConfig: {
        visible: false,
        editData: {}
      },
      detailDialogConfig: {
        visible: false,
        editData: {}
      },
    }
  },
  mounted() {
    this.handleGetList()
  },
  methods: {
    handleSearch() {
      this.listPram.page = 1
      this.handleGetList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.handleGetList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.handleGetList()
    },
    handlerOpenDel(id) {
      this.$confirm('确认删除当前数据').then(() => {
        deleteRow({id}).then(data => {
          this.$message.success('删除数据成功')
          this.handleGetList()
        })
      })
    },
    handleGetList() {
      this.loading=true
      list( this.listPram ).then(data => {
        this.listData.count = data.count
        this.listData.list = data.list
      }).finally(()=>{
        this.loading=false;
      })
    },
    handlerOpenReview(editDate) {
      this.reviewDialogConfig.editData = editDate
      this.reviewDialogConfig.visible = true
    },
    hideReviewDialog() {
      this.reviewDialogConfig.visible = false
      this.handleGetList()
    },
    handlerOpenDetail(editDate) {
      this.detailDialogConfig.editData = editDate
      this.detailDialogConfig.visible = true
    },
    hideDetailDialog() {
      this.detailDialogConfig.visible = false
      this.handleGetList()
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.handleGetList()
    }
  }
}
</script>
